package com.demo.core.service;

import com.demo.core.entity.Person;
import com.demo.core.mapper.PersonMapper;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
import jakarta.transaction.Transactional;

@ApplicationScoped
public class DbService {

    @Inject
    PersonMapper personMapper;

    public Long save(Person person) {
        personMapper.insert(person);
        return person.getId();
    }


    public Person getById(Long id) {
        return personMapper.selectById(id);
    }

    public Boolean remove(Long id){
        return personMapper.deleteById(id)>0;
    }

    @Transactional(rollbackOn = Exception.class)
    public Boolean testTransaction(Person person) {
        this.save(person);
        int i=1/0;
        return null;
    }
}
